home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / TESTPRGS.ZIP / LONGBN2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-14  |  3KB  |  81 lines

  1. PROGRAM LONGPERF;  { Copyright (c) 1992,1993 Norbert Juffa }
  2.  
  3. { Program LONGPERF tests speed of longint operations. This is the TP version. }
  4. { It was compiled using the Turbo Pascal 6.0 compiler using my own run-time   }
  5. { library available as TPL60N19.ZIP from garbo@uwasa.fi. Switches were set    }
  6. { for fastest execution of binary using: $r-,s-,i-,v-,b-,a+                   }
  7.  
  8. { Statistics of longint operations used: }
  9. { add/sub: 8                             }
  10. { mul:     3                             }
  11. { div/mod: 2                             }
  12. { shifts:  2                             }
  13. { bit-ops: 2                             }
  14. { abs val: 2                             }
  15. { ----------                             }
  16. { total:  21                             }
  17.  
  18. {$R-,S-,I-,A+,B-,V-}
  19.  
  20. USES Time;                       { function clock return time in milliseconds }
  21.  
  22. VAR Start, J, K, L, N: LONGINT;
  23.  
  24. BEGIN
  25.    Start := Clock;
  26.    K := 1396878;
  27.    L := 9176;
  28.    J := 8568673;
  29.    FOR N := 0 TO 10000 DO BEGIN
  30.       L := (K * L * J) * (J + K) + K;
  31.       K := ((Abs (K + J + N)) SHR (J AND (Longint(31)))) + L;
  32.       L := Abs (L) SHL (K AND (Longint(31)));
  33.       J := (K * J - L) * (L + K + J);
  34.    END;
  35.    WriteLn ('elapsed: ', Clock-Start, ' ms');
  36.    WriteLn ('actual:', N:9, L:16, J:16, K:16);
  37.    WriteLn ('expected:', 10000:7, 1209532416:16, 1083102604:16, 1421878289:16);
  38. END.
  39.  
  40.  
  41. /* Program LONGPERF tests speed of longint operations. This is the C version. */
  42. /* It was compiled using the Microsoft C/C++ 7.0 optimizing compiler. Switches*/
  43. /* were set for fastest execution of binary using: -Oxazb2 -Gr -AS            */
  44.  
  45. /* Statistics of longint operations used: */
  46. /* add/sub: 8                             */
  47. /* mul:     3                             */
  48. /* div/mod: 2                             */
  49. /* shifts:  2                             */
  50. /* bit-ops: 2                             */
  51. /* abs val: 2                             */
  52. /* ----------                             */
  53. /* total:  21                             */
  54.  
  55.  
  56. #include <stdlib.h>
  57. #include <stdio.h>
  58.  
  59. extern long cdecl extime(void);  /* returns time in milliseconds */
  60. long start,i,j,k,l,n;
  61.  
  62. void main (void)
  63. {
  64.    start = extime();
  65.    k = 1396878;
  66.    l = 9176;
  67.    j = 8568673;
  68.    for (n=0; n<=10000; n++)
  69.       {
  70.       l = (k * l * j) / (j + k) + k;
  71.       k = ((labs (k + j + n)) >> (j & 31L)) + l;
  72.       l = labs(l) << (k & 31L);
  73.       j = (k * j - l) % (l + k +j);
  74.       }
  75.  
  76.    printf ("elapsed: %0ld ms\n", extime()-start);
  77.    printf ("actual: %8ld %15ld %15ld %15ld\n",n,l,j,k);
  78.    printf ("expected: %6ld %15ld %15ld %15ld\n",10000,1209532416,1083102604,1421878289);
  79. }
  80.  
  81.